package Bill.app.client;

import java.awt.Font;
import java.io.BufferedReader;
import java.io.IOException;
import java.net.Socket;
import java.util.Date;
import java.util.StringTokenizer;
import javax.swing.*;

public class GroupChatRecevoir extends Thread
{

    GroupChatRecevoir(BufferedReader lecture, JList message, Socket socket, String Etat)
    {
        this.lecture = null;
        this.message = null;
        this.socket = null;
        this.Etat = null;
        model = new DefaultListModel();
        this.lecture = lecture;
        this.message = message;
        this.socket = socket;
        this.Etat = Etat;
        start();
    }

    public void run()
    {
        do
            try
            {
                String mess = lecture.readLine();
                if(mess.startsWith("info"))
                {
                    StringTokenizer t = new StringTokenizer(mess, ":");
                    t.nextToken();
                    JOptionPane.showMessageDialog(null, t.nextToken());
                } else
                {
                    JLabel abel = new JLabel(mess);
                    abel.setToolTipText((new Date()).toLocaleString());
                    abel.setFont(new Font("SansSerif", 1, 16));
                    model.addElement(abel);
                    message.setModel(model);
                }
            }
            catch(IOException ioexception)
            {
                return;
            }
        while(true);
    }

    BufferedReader lecture;
    JList message;
    Socket socket;
    String Etat;
    DefaultListModel model;
}
